Public Class frmMain
    Private oCMApi As CMApi.clsUtil
    Private oLog As LogHandler.clsLogger
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ceURI As String = "http://" & txtCEIP.Text & ":" & txtCEPort.Text & "/wsi/FNCEWS40MTOM/"
        Dim sSQL As String = ""
        Dim dt As DataTable
        Try
            oLog = New LogHandler.clsLogger
            lvwStatus.Items.Clear()
            oCMApi = New CMApi.clsUtil("c:\CMApiLog", "Trace")
            oCMApi.LogonCE(txtCEUid.Text, txtCEPwd.Text, ceURI)
            While True
                sSQL = "select id,applno,docpages,totalpages from CConsumerLoanT where docpages <> totalpages "
                dt = oCMApi.GetDocList(txtOS.Text, sSQL)
                If dt Is Nothing OrElse dt.Rows.Count = 0 Then
                    Exit While
                End If
                For Each dr As DataRow In dt.Rows
                    Dim oItem As ListViewItem
                    oItem = lvwStatus.Items.Add(dr("id"))
                    oItem.SubItems.Add(dr("docpages"))
                    oItem.SubItems.Add(dr("totalpages"))
                    Dim oProp(0) As CMApi.clsUtil.PropertyInfo
                    oProp(0).PropertyName = "docpages"
                    oProp(0).PropertyValue = Integer.Parse(dr("totalpages"))
                    Try
                        Dim oDoc As FileNet.Api.Core.IDocument
                        oDoc = oCMApi.GetIDocument(txtOS.Text, dr("id"))
                        oCMApi.SetDocProperties(oDoc, oProp)
                        oItem.SubItems.Add("OK")
                        oLog.writeLine("c:\CMApiLog", "UPD", "Update OK;" & dr("applno") & ";" & dr("id") & ";" & dr("docpages") & ";" & dr("totalpages"))
                    Catch ex As Exception
                        oItem.SubItems.Add("FAIL")
                        oLog.writeLine("c:\CMApiLog", "UPD", "Update Fail;" & ex.ToString)
                    End Try
                    Application.DoEvents()
                Next
            End While
        Catch ex As Exception
            txtStatus.Text = ex.ToString
        End Try

    End Sub
End Class
